package com.fas.hehe.system.service;

import java.util.ArrayList;
import java.util.Map;

import org.junit.Assert;

import com.fas.core.BaseService;
import com.fas.core.plugin.datatables.PageRequest;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
/**
 * 系统操作日志业务处理类
 * 
 *
 * @Copyright: Copyright (c) 2016 FAS 
 * @anthor yixiaoping<thinker1013@163.com>
 * @since 2016年1月23日 下午8:10:50
 * @version V1.0
 */
public class OperateLogService extends BaseService {

	/**
	 * 
	 * @Title:分页查询
	 * @Description: 
	 * @param request
	 * @return     
	 * @anthor yixiaoping<thinker163@163.com>
	 * @date 2016年1月23日 下午8:13:24
	 */
    public Page<Record> queryPage(PageRequest request){
            Assert.assertNotNull("请求参数不能为空", request);
            
            Map<String,Object> paramsMap = request.getParams();
            ArrayList<Object> params = new ArrayList<Object>();
            String selectSql = "select * ";
            StringBuffer whereSql = new StringBuffer();
            whereSql.append(" from sys_operate_log where 1=1 ");
            
            if(StrKit.notBlank((String)paramsMap.get("table_name"))){
                    whereSql.append(" and table_name like ?");
                    params.add(this.getLikeValue(paramsMap.get("table_name")));
            }
            
            if(StrKit.notBlank((String)paramsMap.get("account"))){
                    whereSql.append(" and account = ?");
                    params.add(paramsMap.get("account"));
            }
            if(StrKit.notBlank((String)paramsMap.get("log_type"))){
                    whereSql.append(" and log_type = ?");
                    params.add(paramsMap.get("log_type"));
            }
            if(StrKit.notBlank((String)paramsMap.get("begin_opertime"))){
                    whereSql.append(" and log_time >= ?");
                    params.add(paramsMap.get("begin_opertime"));
            }
            if(StrKit.notBlank((String)paramsMap.get("end_opertime"))){
                    whereSql.append(" and log_time <=  ?");
                    params.add(paramsMap.get("end_opertime"));
            }
            
            if(StrKit.notBlank((String)request.getOderby())){
                    whereSql.append(" order by ").append(request.getOderby()) ;
            }
            
            return Db.paginate(request.getPageNumber(), request.getPageSize(), selectSql, whereSql.toString(),params.toArray());
    }
    
}
